using System;
using System.Globalization;
using System.Security.Principal;

using Azure.Domain.Messages;
using Azure.Domain.Models;

namespace Azure.Tests
{
    public static class Test
    {
        public const string Title = "Foo";
        public const string Body = "<p>Bar</p>";
        public const string Author = "Tester";
        public const string Slug = "this-is-a-test-message";

        public static SiteConfiguration Configuration
        {
            get
            {
                return new SiteConfiguration { Email = "test@test.com", Title = "Test Site", Owner = "Joe Boxer" };
            }
        }

        public static NewPostMessage NewPostMessage
        {
            get { return new NewPostMessage { Title = Title, Body = Body, Author = Author, Slug = Slug, Created = DateTime.UtcNow}; }
        }

        public static Post Post
        {
            get { return new Post { PartitionKey = "79899894", RowKey = Slug, Title = Title, Body = Body, Author = Author, Created = DateTime.Parse("January 5, 2010", new CultureInfo("en-US")), Slug = Slug }; }
        }

        public static IPrincipal AuthorizedUser
        {
            get
            {
                return new TestAuthorizedUser();
            }
        } 

        class TestAuthorizedUser : IPrincipal
        {
            private readonly UserIdentity _identity = new UserIdentity();

            public bool IsInRole(string role)
            {
                return true;
            }

            public IIdentity Identity
            {
                get
                {
                    return _identity;
                }
            }

        }

        class UserIdentity : IIdentity
        {
            public string Name
            {
                get
                {
                    return "Test User";
                }
            }

            public string AuthenticationType
            {
                get
                {
                    return "Stubbed";
                }
            }

            public bool IsAuthenticated
            {
                get
                {
                    return true;
                }
            }
        }
    }
}